Imports System
Imports System.Net
Imports System.IO

Public Class WebResponseWrapper
    Inherits WebResponse

    Private wr As WebResponse
    Private response_stream As Stream = Nothing

    Public Sub New(ByVal wrapped As WebResponse)
        wr = wrapped
    End Sub

    Public Overrides Function GetResponseStream() As Stream
        If (response_stream Is Nothing) Then
            response_stream = wr.GetResponseStream()
            If String.Compare(Headers("Content-Encoding"), "gzip", True) = 0 Then _
             response_stream = New ICSharpCode.SharpZipLib.GZip.GZipInputStream(response_stream)
        End If
        Return response_stream
    End Function

    Public Overrides Property ContentLength() As Long
        Get
            Return wr.ContentLength
        End Get
        Set(ByVal Value As Long)
            wr.ContentLength = Value
        End Set
    End Property

    Public Overrides Property ContentType() As String
        Get
            Return wr.ContentType
        End Get
        Set(ByVal Value As String)
            wr.ContentType = Value
        End Set
    End Property

    Public Overrides ReadOnly Property ResponseUri() As Uri
        Get
            Return wr.ResponseUri
        End Get
    End Property

    Public Overrides ReadOnly Property Headers() As WebHeaderCollection
        Get
            Return wr.Headers
        End Get
    End Property
End Class
